﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace StickTops
{

    /// <summary>
    /// Stick top form. Use LoginForm for new program
    /// </summary>
    public partial class StickTop : Form
    {

        #region "Private members"

        private Point LastCursorPosition;
        private bool IsMouseDown = false;

        #endregion

        #region "Constructor"

        public StickTop()
        {
            InitializeComponent();
        }

        public StickTop(NewNote newsettings)
        {
            InitializeComponent();
            this.BackColor = newsettings.MainBack;
            this.MainTextBox.Text = newsettings.MainText;
            this.Location = newsettings.Pos;
            this.Size = newsettings.Size;

            this.MainLabel.ForeColor = newsettings.LabelFore;
            this.MainLabel.BackColor = newsettings.LabelBack;
            this.MainTextBox.ForeColor = newsettings.MainFore;
            this.MainTextBox.BackColor = newsettings.MainBack;
            this.ResizePic.BackColor = newsettings.MainBack;

            this.MainTextBox.SelectionLength = 0;
            this.MainTextBox.Select(MainTextBox.Text.Length, MainTextBox.Text.Length);
        }

        #endregion

        #region "Private Methods"


        private void MainTextBox_TextChanged(object sender, EventArgs e)
            {
                if (MainTextBox.Text != "")
                {
                    MainLabel.Text = MainTextBox.Lines[0];
                }
                else MainLabel.Text = "NoName";
            }
        

        # endregion

        #region "Move"

        private void MainLabel_MouseDown(object sender, MouseEventArgs e)
        {
            this.IsMouseDown = true;
            this.LastCursorPosition = new Point(e.X, e.Y);
        }

        private void MainLabel_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.IsMouseDown == true)
            {
                 //Move the form
                 this.Location = new Point(this.Left - (this.LastCursorPosition.X - e.X), this.Top - (this.LastCursorPosition.Y - e.Y));
                 
                 //Redraw the form//
                 this.Invalidate();
            }

}

        private void MainLabel_MouseUp(object sender, MouseEventArgs e) 
        {
             this.IsMouseDown = false;
        }

        #endregion

        #region "Resize"

            private void ResizePic_MouseDown(object sender, MouseEventArgs e)
            {
                IsMouseDown = true;
                this.LastCursorPosition = new Point(e.X, e.Y);
            }

            private void ResizePic_MouseMove(object sender, MouseEventArgs e)
            {
                if (this.IsMouseDown == true)
                {

                        //Resize the form
                        this.Size = new Size(this.Size.Width + (e.X - LastCursorPosition.X), this.Size.Height + (e.Y - LastCursorPosition.Y));
                        //Redraw the form//
                        this.Invalidate();
                   
                }
            }

            private void ResizePic_MouseUp(object sender, MouseEventArgs e)
            {
                this.IsMouseDown = false;
            }
        #endregion

        #region "Menu"

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
                    {
                        MainForm.Instance.MakeNewNote();
                    }

        private void MenuItemSave_Click(object sender, EventArgs e)
        {
            MainForm.Instance.SaveNotes(true);
        }

        private void CloseStripMenuItem_Click(object sender, EventArgs e)
                    {
                        MainTextBox.Text = "";
                        this.Close();
                    }

        #region "Color"

            private void topTextToolStripMenuItem_Click(object sender, EventArgs e)
            {
                ColorDialog ColorDia = new ColorDialog();
                ColorDia.AllowFullOpen = true;
                ColorDia.Color = Properties.Settings.Default.LabelFore;
                ColorDia.ShowDialog();

                MainLabel.ForeColor = ColorDia.Color;
                Properties.Settings.Default.LabelFore = ColorDia.Color;
            }

            private void topBackgroundToolStripMenuItem_Click(object sender, EventArgs e)
            {
                ColorDialog ColorDia = new ColorDialog();
                ColorDia.AllowFullOpen = true;
                ColorDia.Color = Properties.Settings.Default.LabelBack;
                ColorDia.ShowDialog();

                MainLabel.BackColor = ColorDia.Color;
                Properties.Settings.Default.LabelBack = ColorDia.Color;
            }

            private void bottomTextToolStripMenuItem_Click(object sender, EventArgs e)
            {
                ColorDialog ColorDia = new ColorDialog();
                ColorDia.AllowFullOpen = true;
                ColorDia.Color = Properties.Settings.Default.MainFore;
                ColorDia.ShowDialog();

                MainTextBox.ForeColor = ColorDia.Color;
                Properties.Settings.Default.MainFore = ColorDia.Color;
            }

            private void bottomBackgroundToolStripMenuItem_Click(object sender, EventArgs e)
            {
                ColorDialog ColorDia = new ColorDialog();
                ColorDia.AllowFullOpen = true;
                ColorDia.Color = Properties.Settings.Default.MainBack;
                ColorDia.ShowDialog();

                MainTextBox.BackColor = ColorDia.Color;
                Properties.Settings.Default.MainBack = ColorDia.Color;
                ResizePic.BackColor = ColorDia.Color;
            }

#endregion

        #endregion
        
        #region "public methods"

        public string MainText()
        {
            return MainTextBox.Text;
        }

        public string GetColors()
        {
            string finalColors = this.MainLabel.ForeColor.ToArgb().ToString() + "," +
                                 this.MainLabel.BackColor.ToArgb().ToString() + "," +
                                 this.MainTextBox.ForeColor.ToArgb().ToString() + "," +
                                 this.MainTextBox.BackColor.ToArgb().ToString();
            return finalColors;
        }
        
        #endregion

    }

        
}

